﻿<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl" >
  <xsl:output version="4.0" method="html" indent="no"  omit-xml-declaration="yes" encoding="UTF-8" doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN" doctype-system="http://www.w3.org/TR/html4/loose.dtd"/>
  
   <xsl:template match="PatientDemographicsServicePatientDemographics">
     <div id="patientlabel" class="clearfix">
       <h1>
        <xsl:value-of select="name/title"/>&#160;<xsl:value-of select="name/givenNames"/>&#160;<xsl:value-of select="name/familyName"/>
       </h1>
       <div id="patientaddress" class="clearfix" style="float:none;">
          <xsl:value-of select="address/addressLine1"/>,&#160;
          <xsl:value-of select="address/addressLine2"/>,&#160;
          <xsl:value-of select="address/addressLine3"/>,&#160;
          <xsl:value-of select="address/addressLine4"/>,&#160;
          <xsl:value-of select="address/postcode"/>
       </div>
       <div id="patientpasdetails" class="clearfix" style="float:none;">
         <xsl:for-each select="patientID">
           <xsl:variable name="domainname" select="identifierValue/domainForIdentifier/domainName"/>
           <xsl:if test="normalize-space($domainname) = ''">
             <label>
               NHS Number:
             </label>
             <xsl:value-of select="identifierValue/identifier"/>
             <br/>
           </xsl:if>
           <xsl:if test="$domainname!=''">
             <label>
               PAS Number:
             </label>
             <xsl:value-of select="identifierValue/identifier"/>
             <br/>
           </xsl:if>
         </xsl:for-each>
         <label>Gender:</label><xsl:value-of select="gender/gender/rubric"/><br/>
         <label>DOB:</label><xsl:value-of select="dob/dateOfBirth/timepoint"/><br/>
       </div>
       <div id="patientpascareagentdetails" class="clearfix">
         <label>GP:</label>
         <div style="float:left">
         <xsl:value-of select="CareAgent/agentName"/>
         <br/>
           <xsl:call-template name="SplitText">
             <xsl:with-param name="inputString" select="CareAgentContact/careAgent/agentName"/>
           </xsl:call-template>
         </div>
       </div>
     </div>
   </xsl:template>


  <xsl:template name="SplitText">
    <xsl:param name="inputString"/>
    <xsl:choose>
      <xsl:when test="contains($inputString, ',')">
        <xsl:value-of select="substring-before($inputString,',')"/><br/>
        <xsl:text disable-output-escaping = "no"> </xsl:text>
        <xsl:call-template name="SplitText">
          <xsl:with-param name="inputString" select="substring-after($inputString,',')"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:choose>
          <xsl:when test="$inputString = ''">
            <xsl:text></xsl:text>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$inputString"/>
            <xsl:text> </xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>


</xsl:stylesheet>


  

